﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Air_condition.DO;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace Air_condition.DO
{
    [Serializable]
    public class Alternative : ICloneable
    {
        // Attributes of Alternative ofject (private)
        private string sname;
        private string sdescription;
        private string sbuildingowner;
        private string sproject;
        private string slocation;
        private int ilocation;
        private double dbcoldProductivity = 0;
        public List<Room> lRoom = new List<Room>();

        // Public access to attributes
        public string sLocation
        {
            get { return slocation; }
            set { slocation = value; }
        }

        public string sName
        {
            get { return sname; }
            set { sname = value; }
        }

        public string sDescription
        {
            get { return sdescription; }
            set { sdescription = value; }
        }

        public string sBuildingowner
        {
            get { return sbuildingowner; }
            set { sbuildingowner = value; }
        }

        public string sProject
        {
            get { return sproject; }
            set { sproject = value; }
        }

        public int iLocation
        {
            get { return ilocation; }
            set { ilocation = value; }
        }

        public double dbColdProductivity
        {

            get { return dbcoldProductivity; }
            set { dbcoldProductivity = value; }
        }

        /// <summary>
        /// Method to calculate sum cold productivity
        /// </summary>
        public void CalculationSumColdProductivity()
        {
            foreach (Room r in lRoom)
            {
                dbcoldProductivity += r.CalculateColdProductivity();
            }
        }

        /// <summary>
        /// Method to add a room into list room
        /// </summary>
        /// <param name="room">room object that need to add into list room</param>
        public void AddRoom(Room room)
        {
            lRoom.Add(room);
        }

        /// <summary>
        /// Method to remove a room from list room
        /// </summary>
        /// <param name="room">room object that need to remove from list room</param>
        public void DeleteRoom(Room room)
        {
            lRoom.Remove(room);
        }

        /// <summary>
        /// method to copy Alternative object to a new object
        /// </summary>
        /// <returns>a new object is Alternative Object type</returns>
        public object Clone()
        {
            object clone;
            try
            {
                using (MemoryStream stream = new MemoryStream())
                {

                    BinaryFormatter formatter = new BinaryFormatter();

                    // Serialize this object

                    formatter.Serialize(stream, this);

                    stream.Position = 0;

                    // Deserialize to another object

                    clone = formatter.Deserialize(stream);

                }
                return clone;
            }
            catch (Exception e)
            {
                return e;
            }

        }
    }
}
